package com.baichen.bio;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class BioClient {
    public static void main(String[] args) throws IOException {
        Thread thread = startClient();
        thread.start();
    }

    private static Thread startClient() throws IOException {
        Thread thread = new Thread(() -> {
            try (Socket socket = new Socket()) {
                socket.connect(new InetSocketAddress("localhost", 8888));
                String message = "Hello, Bio Server!";
                OutputStream outputStream = socket.getOutputStream();
                for (int i = 0; i < 10; i++) {
                    outputStream.write(message.getBytes());
                    outputStream.flush();
//                    Thread.sleep(200);
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        return thread;
    }
}
